package com.zc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zc.dao.IPowerFactorDao;
import com.zc.domain.DoubleListData;
import com.zc.domain.FaultItem;
import com.zc.domain.FourPointsItem;
import com.zc.domain.Item;
import com.zc.domain.TwoPointsItem;
import com.zc.service.PowerFactorService;
import com.zc.service.RedisService;

@Controller
public class PowerFactorController {
	@Autowired
	private PowerFactorService powerFactorService;
	@Autowired
	private RedisService redisService;
	
	@RequestMapping(value = "/getSubPowerFactor",method = RequestMethod.POST)
    public @ResponseBody List<Item> getSubPowerFactor(){       	
		String key="subPowerFactorData";
		List<Item> subPowerFactorData=null;
		if(redisService.hasKey(key)){
			subPowerFactorData=(List<Item>) redisService.get(key);
		}		
		else {
			subPowerFactorData=powerFactorService.getSubPowerFactor();
			redisService.set(key, subPowerFactorData);
		}
		return subPowerFactorData;
    }
	
	@RequestMapping(value = "/getMainPowerFactor",method = RequestMethod.POST)
    public @ResponseBody List<Item> getMainPowerFactor(){       	
		String key="mainPowerFactorData";
		List<Item> mainPowerFactorData=null;
		if(redisService.hasKey(key)){
			mainPowerFactorData=(List<Item>) redisService.get(key);
		}		
		else {
			mainPowerFactorData=powerFactorService.getMainPowerFactor();
			redisService.set(key, mainPowerFactorData);
		}
		return mainPowerFactorData;
    }

}
